package com.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import com.domain.bo.ResearchServiceBo;
import com.domain.entity.ResearchService;
import com.domain.vo.ResServListVo;
import com.service.IResearchServService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 科研服务Controller
 *
 * @author ruoyi
 * @date 2025-05-27
 */

@Api(tags = "科研服务")
@RestController
@RequestMapping("/research/service")
public class ResearchServController extends BaseController {

    @Autowired
    private IResearchServService researchServService;

    /**
     * 列表左上方统计
     */
    @ApiOperation("列表左上方统计")
    @GetMapping("/groups")
    public AjaxResult groups(ResearchServiceBo researchServiceBo){
        return success(researchServService.selectGroups(researchServiceBo));
    }

    /**
     * 查询科研服务列表
     */
    @ApiOperation("查询科研服务列表")
    @GetMapping("/list")
    public TableDataInfo list(ResearchServiceBo researchServiceBo)
    {
        IPage<ResServListVo> proList = researchServService.selectList(researchServiceBo,"list");
        return TableDataInfo.build(proList.getRecords(),proList.getTotal());
    }

    /**
     * 导出科研服务列表
     */
    @ApiOperation("导出科研服务列表")
    @Log(title = "科研服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody ResearchServiceBo researchServiceBo)
    {
        IPage<ResServListVo> list = researchServService.selectList(researchServiceBo,"export");
        ExcelUtil<ResServListVo> util = new ExcelUtil<>(ResServListVo.class);
        util.showColumn(researchServiceBo.getExportStr().split(","));
        util.exportExcelByOrder(response, list.getRecords(), "科研服务数据",researchServiceBo.getExportStr().split(","));
    }

    /**
     * 获取科研服务详细信息
     */
    @ApiOperation("获取详情")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(researchServService.selectResearchServiceByID(ID));
    }

    /**
     * 保存科研服务
     */
    @ApiOperation("保存科研服务")
    @Log(title = "科研服务", businessType = BusinessType.INSERT)
    @PostMapping("/saveResServ")
    public AjaxResult saveResServ(@RequestBody ResearchService researchService)
    {
        return researchServService.saveResServ(researchService);
    }

    /**
     * 删除科研服务
     */
    @ApiOperation("批量删除")
    @Log(title = "科研服务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        String res = researchServService.deleteResServByIDs(IDs);
        if(res.contains("成功")){
            return success(res);
        }else{
            return error(res);
        }
    }
}
